package pl.alef.mindplay.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.MapKeyColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;


@Entity
@Table(name="visit")
@Access(AccessType.FIELD)
public class Visit implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)	
	private Long id;
		
	@ManyToOne
	@JoinColumn(name="id_user_agent")
	private UserAgent userAgent;

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_referer")
	private Referer referer;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_visitor")
	private Visitor visitor;
	
	@Column(name="date_start", updatable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateStart;
	
	@Column(name="date_end")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateEnd;

	
	@OneToMany(mappedBy="visit", cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
	@MapKey(name="type")
	private Map<String, RemoteAddress> addresses = new HashMap<String, RemoteAddress>(19);
	
	private int cnt;
	
	
	
	public UserAgent getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(UserAgent userAgent) {
		this.userAgent = userAgent;
	}

	public Date getDateStart() {
		return dateStart;
	}

	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}
	
	public Date getDateEnd() {
		return dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Visitor getVisitor() {
		return visitor;
	}

	public void setVisitor(Visitor visitor) {
		this.visitor = visitor;
	}

	public int getCnt() {
		return cnt;
	}

	public void setCnt(int cnt) {
		this.cnt = cnt;
	}

	public Referer getReferer() {
		return referer;
	}

	public void setReferer(Referer referer) {
		this.referer = referer;
	}

	public Map<String, RemoteAddress> getAddresses() {
		return addresses;
	}

	public void setAddresses(Map<String, RemoteAddress> addresses) {
		this.addresses = addresses;
	}
	
}
